package com.niit.cms.controller;

import com.niit.cms.entity.*;
import com.niit.cms.service.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: cao_jiaqi
 * @CreateTime： 2022/6/23 13:24
 */
@Controller
public class IndexController {
    @Resource
    private SlideshowService slideshowService;
    @Resource
    private CourseService courseService;
    @Resource
    private ClassificationService classificationService;
    @Resource
    private KeywordService keywordService;
    @Resource
    private NewsService newsService;
    /**
     * @Description: 向首页返回轮播图，课程，分类，资讯信息
     * @Author: cao_jiaqi
     * @CreateTime: 2022/6/23 16:38
     * @param: model
     * @return: java.lang.String
     **/
    @GetMapping("/index")
    public String index(Model model){
        //查询首页轮播图
        List<Slideshow> slideshowList = slideshowService.queryList();
        System.out.println("slideshowList " + slideshowList);
        model.addAttribute("slideshowList", slideshowList);
        //查询首页展示课程
        List<Course> courseList = courseService.queryOrderedListByCourseLimit(new Course(), "people_num", 4);
        System.out.println("courseList " + courseList);
        model.addAttribute("courseList", courseList);
        //查询首页一级分类
        List<Classification> classificationList = classificationService.queryListByParentId(0);
        System.out.println("classificationList " + classificationList);
        model.addAttribute("classificationList", classificationList);
        //查询首页搜索关键词
        List<Keyword> keywordList = keywordService.queryList();
        model.addAttribute("keywordList", keywordList);
        //首页‘找课程’查询一级分类下指定条课程，默认父分类id为1
        List<Course> courseList1 = courseService.queryOrderedListByTypeLimit(1, "people_num", 7);
        model.addAttribute("courseList1", courseList1);
        //首页根据分类查询新闻
        List<News> newsList = newsService.queryOrderedListByLmit("pubdate", 25);
        model.addAttribute("newsList", newsList);
        return "index";
    }
}
